<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="com.laundry.tables.Booking"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.laundry.lib.FreeSlot"%>
<%@page import="sun.misc.Regexp"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.16.custom.min.js"></script>

</head>
<body>


<script type="text/javascript"> function test() { window.alert('hi'); return true;}
function submitForm(){
	document.forms["frm1"].submit();
	return true;
}

function bookSlot(){

	document.forms["frm1"].action="book.jsp";
	document.forms["frm1"].submit();
	return true;
}
</script>
<table border="2" align="center">
<thead align="center" > LRS </thead>
	<tr ><td>date picker </td> <td> dropdown </td> </tr>
	<tr  align="center"><td> Submit button </td></tr>

</table>
<form action="book.jsp" id="booking" method="post" name="booking1"></form>
<form action="index.jsp"  id="frm1"  method=post name="form23">
<input type="text" name="datepicker" value="<% if(request.getParameter("datepicker")!=null){out.print(request.getParameter("datepicker"));} %>" id="datepicker"  onchange="submitForm();" />
<select name="selAvailableSlots"> 
<% 
 
 String date= request.getParameter("datepicker");
 if(date!=null){
	
	 String[] str =  date.split("/");
	 int imonth=Integer.parseInt(str[0])-1;
	 int idate = Integer.parseInt(str[1]);
	 int iyear=Integer.parseInt(str[2])-1900;
	 
	 Booking b=  Booking.instantiate();
	 
	 ArrayList<FreeSlot> freeSlots=  b.getFreeSlots(new Date(iyear,imonth,idate));
 	for(FreeSlot freeSlot: freeSlots){	 
 
%>
<option value="<%= freeSlot.getSlot().getId() %>">  <%= freeSlot.getSlot().getFrom() %> - <%= freeSlot.getSlot().getTo() %> ( <%= freeSlot.getCount() %> )</option>  
<%} 
 }
 else {
	 

%>
<option value="">Please select a date </option>
<% } %>
</select>

<input type="button"  id="sb1" value="Book" onclick="bookSlot();"/>

</form>
	

<script>
	$(function() {
		$( "#datepicker" ).datepicker();
	});
	</script>
</body>
</html>